<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin_category extends Admin_Controller
{
	public function __construct()
	{
		parent::__construct();
		$this->load->library('category');
	}

	public function index()
	{
		$this->caidan_list();
	}

	public function category_list($pid = 0)
	{
		$data['pid'] = $pid;
		$data['cate'] = $this->category->getAllCategory($pid, false, 1);
		$this->load->view('cate', $data);
	}

    public function category_list_1($pid = 0)
    {
        $data['pid'] = $pid;
        $data['cate'] = $this->category->getAllCategory($pid, false, 1, false, 1);
        $this->load->view('cate', $data);
    }
    public function category_list_3($pid = 0)
    {
        $data['pid'] = $pid;
        $data['cate'] = $this->category->getAllCategory($pid, false, 1, false, 3);
        $this->load->view('cate', $data);
    }
    //添加分类
    public function category_add($id = '')
    {
    	if ($this->input->post('submit') == 'OK')
    	{
    		//获取表单提交的信息
            $fatherId = $this->input->post('fatherId');
            $cateName = $this->input->post('cateName');
            $content = $this->input->post('content');
            $sort = $this->input->post('sort');
            $display = $this->input->post('display');
            $ctype = $this->input->post('ctype');
            if ($this->category->addCategory($fatherId,$cateName,$content,$sort,$display,$ctype) > 0) 
            {
                $this->_jui_message('操作成功');
            } 
            else 
            {
                $this->_jui_message('操作失败', 'error');
            }
        }
        else
        {

	        $query = $data['post'] = 0;
			$data['option_str'] = $this->category->getOptionStr($id,true,0,false);

	        $this->load->view('cate_edit',$data);
    	}
    }	

    public function category_edit($cid = '')
    {
    	if ($this->input->post('submit') == 'OK')
    	{
            //获取表单提交的信息
			$fatherId = $this->input->post('fatherId');
            $cateName = $this->input->post('cateName');
            $content = $this->input->post('content');
            $sort = $this->input->post('sort');
            $display = $this->input->post('display');
            $ctype = $this->input->post('ctype');

            if ($this->category->editCategory($cid,$fatherId,$cateName,$content,$sort,$display,$ctype) > 0) 
            {
				$this->_jui_message('操作成功');
            } 
            else 
            {
                $this->_jui_message('操作失败', 'error');
            }
        }
        else
        {
	        $query = $data['post'] = $this->category->fetchOne($cid);
	        $pid = $query['fatherId'];
			$data['option_str'] = $this->category->getOptionStr($pid,true,0,false);

	        $this->load->view('cate_edit',$data);
    	}
    }

    public function category_del($cid = '') 
    {
        if ($cid !== '') {
            if ($this->category->delCategory($cid) > 0) {
                $this->_jui_message('操作成功');
            } 
            else 
            {
                $this->_jui_message('操作成功', 'error');
            }
        }
	}



}

/* End of file caipu.php */
/* Location: ./application/controllers/manage/caipu.php */